<?php
/**
 *	KLF Framework
 *
 *	Written by Kristian Oye <kristianoye@gmail.com> on Oct 30; 2011
 *	Copyright (C) 2010-2011
 */
namespace KLF\System\Web
{
	use KLF\System\KType;

	use KLF\System\KEnum;
	use KLF\System\Errors\KInvalidOperationException;
	
	/**
	 *  Class KHttpRequestHeader
	 *
	 *  A static collection of named headers.
	 *
	 *  @package KLF\System\Web
	 *  @access public
	 *  @author Kristian Oye <kristianoye@gmail.com>
	 *  @since 0.1
	 *  
	 *  @method KHttpRequestHeader Accept
	 *  @method KHttpRequestHeader AcceptCharset
	 *  @method KHttpRequestHeader AcceptEncoding
	 *  @method KHttpRequestHeader AcceptLanguage
	 *  @method KHttpRequestHeader Allow
	 *  @method KHttpRequestHeader Authorization
	 *  @method KHttpRequestHeader CacheControl
	 *  @method KHttpRequestHeader Connection
	 *  @method KHttpRequestHeader ContentEncoding
	 *  @method KHttpRequestHeader ContentLanguage
	 *  @method KHttpRequestHeader ContentLength
	 *  @method KHttpRequestHeader ContentLocation
	 *  @method KHttpRequestHeader ContentMd5
	 *  @method KHttpRequestHeader ContentRange
	 *  @method KHttpRequestHeader ContentType
	 *  @method KHttpRequestHeader Cookie
	 *  @method KHttpRequestHeader Date
	 *  @method KHttpRequestHeader Expect
	 *  @method KHttpRequestHeader Expires
	 *  @method KHttpRequestHeader From
	 *  @method KHttpRequestHeader Host
	 *  @method KHttpRequestHeader IfMatch
	 *  @method KHttpRequestHeader IfModifiedSInce
	 *  @method KHttpRequestHeader IfNoneMatch
	 *  @method KHttpRequestHeader IfRange
	 *  @method KHttpRequestHeader IfUnmodifiedSince
	 *  @method KHttpRequestHeader KeepAlive
	 *  @method KHttpRequestHeader LastModified
	 *  @method KHttpRequestHeader MaxForwards
	 *  @method KHttpRequestHeader Pragma
	 *  @method KHttpRequestHeader ProxyAuthorization
	 *  @method KHttpRequestHeader Range
	 *  @method KHttpRequestHeader Referer
	 *  @method KHttpRequestHeader Te
	 *  @method KHttpRequestHeader Trailer
	 *  @method KHttpRequestHeader TransferEncoding
	 *  @method KHttpRequestHeader Translate
	 *  @method KHttpRequestHeader Upgrade
	 *  @method KHttpRequestHeader UserAgent
	 *  @method KHttpRequestHeader Via
	 *  @method KHttpRequestHeader Warning
	 */
	class KHttpRequestHeader extends KEnum
	{
		// Summary:
		//     The Cache-Control header; which specifies directives that must be obeyed
		//     by all cache control mechanisms along the request/response chain.
		const CacheControl = 0;
		//
		// Summary:
		//     The Connection header; which specifies options that are desired for a particular
		//     connection.
		const Connection = 1;
		//
		// Summary:
		//     The Date header; which specifies the date and time at which the request originated.
		const Date = 2;
		//
		// Summary:
		//     The Keep-Alive header; which specifies a parameter used into order to maintain
		//     a persistent connection.
		const KeepAlive = 3;
		//
		// Summary:
		//     The Pragma header; which specifies implementation-specific directives that
		//     might apply to any agent along the request/response chain.
		const Pragma = 4;
		//
		// Summary:
		//     The Trailer header; which specifies the header fields present in the trailer
		//     of a message encoded with chunked transfer-coding.
		const Trailer = 5;
		//
		// Summary:
		//     The Transfer-Encoding header; which specifies what (if any) type of transformation
		//     that has been applied to the message body.
		const TransferEncoding = 6;
		//
		// Summary:
		//     The Upgrade header; which specifies additional communications protocols that
		//     the client supports.
		const Upgrade = 7;
		//
		// Summary:
		//     The Via header; which specifies intermediate protocols to be used by gateway
		//     and proxy agents.
		const Via = 8;
		//
		// Summary:
		//     The Warning header; which specifies additional information about that status
		//     or transformation of a message that might not be reflected in the message.
		const Warning = 9;
		//
		// Summary:
		//     The Allow header; which specifies the set of HTTP methods supported.
		const Allow = 10;
		//
		// Summary:
		//     The Content-Length header; which specifies the length; in bytes; of the accompanying
		//     body data.
		const ContentLength = 11;
		//
		// Summary:
		//     The Content-Type header; which specifies the MIME type of the accompanying
		//     body data.
		const ContentType = 12;
		//
		// Summary:
		//     The Content-Encoding header; which specifies the encodings that have been
		//     applied to the accompanying body data.
		const ContentEncoding = 13;
		//
		// Summary:
		//     The Content-Langauge header; which specifies the natural language(s) of the
		//     accompanying body data.
		const ContentLanguage = 14;
		//
		// Summary:
		//     The Content-Location header; which specifies a URI from which the accompanying
		//     body may be obtained.
		const ContentLocation = 15;
		//
		// Summary:
		//     The Content-MD5 header; which specifies the MD5 digest of the accompanying
		//     body data; for the purpose of providing an end-to-end message integrity check.
		const ContentMd5 = 16;
		//
		// Summary:
		//     The Content-Range header; which specifies where in the full body the accompanying
		//     partial body data should be applied.
		const ContentRange = 17;
		//
		// Summary:
		//     The Expires header; which specifies the date and time after which the accompanying
		//     body data should be considered stale.
		const Expires = 18;
		//
		// Summary:
		//     The Last-Modified header; which specifies the date and time at which the
		//     accompanying body data was last modified.
		const LastModified = 19;
		//
		// Summary:
		//     The Accept header; which specifies the MIME types that are acceptable for
		//     the response.
		const Accept = 20;
		//
		// Summary:
		//     The Accept-Charset header; which specifies the character sets that are acceptable
		//     for the response.
		const AcceptCharset = 21;
		//
		// Summary:
		//     The Accept-Encoding header; which specifies the content encodings that are
		//     acceptable for the response.
		const AcceptEncoding = 22;
		//
		// Summary:
		//     The Accept-Langauge header; which specifies that natural languages that are
		//     preferred for the response.
		const AcceptLanguage = 23;
		//
		// Summary:
		//     The Authorization header; which specifies the credentials that the client
		//     presents in order to authenticate itself to the server.
		const Authorization = 24;
		//
		// Summary:
		//     The Cookie header; which specifies cookie data presented to the server.
		const Cookie = 25;
		//
		// Summary:
		//     The Expect header; which specifies particular server behaviors that are required
		//     by the client.
		const Expect = 26;
		//
		// Summary:
		//     The From header; which specifies an Internet E-mail address for the human
		//     user who controls the requesting user agent.
		const From = 27;
		//
		// Summary:
		//     The Host header; which specifies the host name and port number of the resource
		//     being requested.
		const Host = 28;
		//
		// Summary:
		//     The If-Match header; which specifies that the requested operation should
		//     be performed only if the client's cached copy of the indicated resource is
		//     current.
		const IfMatch = 29;
		//
		// Summary:
		//     The If-Modified-Since header; which specifies that the requested operation
		//     should be performed only if the requested resource has been modified since
		//     the indicated data and time.
		const IfModifiedSince = 30;
		//
		// Summary:
		//     The If-None-Match header; which specifies that the requested operation should
		//     be performed only if none of client's cached copies of the indicated resources
		//     are current.
		const IfNoneMatch = 31;
		//
		// Summary:
		//     The If-Range header; which specifies that only the specified range of the
		//     requested resource should be sent; if the client's cached copy is current.
		const IfRange = 32;
		//
		// Summary:
		//     The If-Unmodified-Since header; which specifies that the requested operation
		//     should be performed only if the requested resource has not been modified
		//     since the indicated date and time.
		const IfUnmodifiedSince = 33;
		//
		// Summary:
		//     The Max-Forwards header; which specifies an integer indicating the remaining
		//     number of times that this request may be forwarded.
		const MaxForwards = 34;
		//
		// Summary:
		//     The Proxy-Authorization header; which specifies the credentials that the
		//     client presents in order to authenticate itself to a proxy.
		const ProxyAuthorization = 35;
		//
		// Summary:
		//     The Referer header; which specifies the URI of the resource from which the
		//     request URI was obtained.
		const Referer = 36;
		//
		// Summary:
		//     The Range header; which specifies the the sub-range(s) of the response that
		//     the client requests be returned in lieu of the entire response.
		const Range = 37;
		//
		// Summary:
		//     The TE header; which specifies the transfer encodings that are acceptable
		//     for the response.
		const Te = 38;
		//
		// Summary:
		//     The Translate header; a Microsoft extension to the HTTP specification used
		//     in conjunction with WebDAV functionality.
		const Translate = 39;
		//
		// Summary:
		//     The User-Agent header; which specifies information about the client agent.
		const UserAgent = 40;
        
        /**
         * Converts the header into a string.
         * 
         * @param KEnum|int $arg
         * @throws KInvalidOperationException
         * @return string
         */
        public static function GetHeaderString($arg)
        {
        	if (is_int($arg))
        	{
        		$value = $arg;
        	}
        	else if(KType::GetType($arg))
        	{
        		$value = $arg->GetValue();
        	}
        	
        	switch ($value)
        	{
        		case KHttpRequestHeader::CacheControl:
        			return "cache-control";
        	
        		case KHttpRequestHeader::Connection:
        			return "connection";
        	
        		case KHttpRequestHeader::Date:
        			return "date";
        	
        		case KHttpRequestHeader::KeepAlive:
        			return "keep-alive";
        	
        		case KHttpRequestHeader::Pragma:
        			return "pragma";
        	
        		case KHttpRequestHeader::Trailer:
        			return "trailer";
        	
        		case KHttpRequestHeader::TransferEncoding:
        			return "transfer-encoding";
        	
        		case KHttpRequestHeader::Upgrade:
        			return "upgrade";
        	
        		case KHttpRequestHeader::Via:
        			return "via";
        	
        		case KHttpRequestHeader::Warning:
        			return "warning";
        	
        		case KHttpRequestHeader::Allow:
        			return "allow";
        	
        		case KHttpRequestHeader::ContentLength:
        			return "content-length";
        	
        		case KHttpRequestHeader::ContentType:
        			return "content-type";
        	
        		case KHttpRequestHeader::ContentEncoding:
        			return "content-encoding";
        	
        		case KHttpRequestHeader::ContentLanguage:
        			return "content-language";
        	
        		case KHttpRequestHeader::ContentLocation:
        			return "content-location";
        	
        		case KHttpRequestHeader::ContentMd5:
        			return "content-md5";
        	
        		case KHttpRequestHeader::ContentRange:
        			return "content-range";
        	
        		case KHttpRequestHeader::Expires:
        			return "expires";
        	
        		case KHttpRequestHeader::LastModified:
        			return "last-modified";
        	
        		case KHttpRequestHeader::Accept:
        			return "accept";
        	
        		case KHttpRequestHeader::AcceptCharset:
        			return "accept-charset";
        	
        		case KHttpRequestHeader::AcceptEncoding:
        			return "accept-encoding";
        	
        		case KHttpRequestHeader::AcceptLanguage:
        			return "accept-language";
        	
        		case KHttpRequestHeader::Authorization:
        			return "authorization";
        	
        		case KHttpRequestHeader::Cookie:
        			return "cookie";
        	
        		case KHttpRequestHeader::Expect:
        			return "expect";
        	
        		case KHttpRequestHeader::From:
        			return "from";
        	
        		case KHttpRequestHeader::Host:
        			return "host";
        	
        		case KHttpRequestHeader::IfMatch:
        			return "if-match";
        	
        		case KHttpRequestHeader::IfModifiedSince:
        			return "if-modified-since";
        	
        		case KHttpRequestHeader::IfNoneMatch:
        			return "if-none-match";
        	
        		case KHttpRequestHeader::IfRange:
        			return "if-range";
        	
        		case KHttpRequestHeader::IfUnmodifiedSince:
        			return "if-unmodified-since";
        	
        		case KHttpRequestHeader::MaxForwards:
        			return "max-forwards";
        	
        		case KHttpRequestHeader::ProxyAuthorization:
        			return "proxy-authorization";
        	
        		case KHttpRequestHeader::Referer:
        			return "referer";
        	
        		case KHttpRequestHeader::Range:
        			return "range";
        	
        		case KHttpRequestHeader::Te:
        			return "te";
        	
        		case KHttpRequestHeader::Translate:
        			return "translate";
        	
        		case KHttpRequestHeader::UserAgent:
        			return "user-agent";
        	
        		default:
        			throw new KInvalidOperationException();
        	}
        }
        
        /**
         * Returns the header string.
         * 
         * @return string
         */
        public function GetHeader()
        {
        	return self::GetHeaderString($this);
        }
    }
}